package com.siscoe.web.managedbean;

import java.beans.ConstructorProperties;
import java.io.IOException;
import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

/**
 * Clase Navigation Bean
 * @author konda
 *
 */
@ManagedBean(name="navigationBean")
@RequestScoped
public class NavigationBean implements Serializable {

  
   
  private static final long serialVersionUID = 1L;
  

  private String title;
  private String urlNavigation;
  
  @PostConstruct
  public void NavigationBean()
  {
	  System.out.println("navigation bean");
	  System.out.println("inicio de navigation bean");
	  if(getUrlNavigation()==null)
		  setUrlNavigation("departamento");
	  else
	  {
		  System.out.println("no es nullo");
	  }
	  
	  System.out.println("urlNavigation=>"+urlNavigation);
	 
  }
  
  
  
  
 
  public void urlAction() 
  {
	  
	  try
	  {
	  System.out.println("Url Navigation"+getUrlNavigation());
	  String renderKitId = FacesContext.getCurrentInstance().getViewRoot().getRenderKitId();
      
	  System.out.println("urlNavigation "+urlNavigation + "renderkit "+FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath().toString());
	  FacesContext.getCurrentInstance().getExternalContext().redirect(urlNavigation+".xhtml");
	  
	  System.out.println("NavigationBean"+this.urlNavigation);
	  }
	  catch(Exception ex)
	  {
		  System.out.println("error xhtml");
	  }
  }
  
  
  
  /**
   * Metodo que permite obtener el action listener 
   * del header y asignar la pagina a cual navegara
   */
  public void urlActionMenu()
  {
	  FacesContext context = FacesContext.getCurrentInstance();
      String selectedPage = context.getExternalContext().getRequestParameterMap().get("page");
      System.out.println("SelectPage => "+selectedPage);
      setUrlNavigation(selectedPage);
  }
  
  
  public void redirect(String redirect)
  {
	  try
	  {
	  FacesContext fc = FacesContext.getCurrentInstance();
	  ExternalContext ec = fc.getExternalContext();
	  ec.redirect(redirect);
	  }catch(Exception ex)
	  {
		  
	  }
  }
  
/***************************/
public String getTitle() {
	return title;
}
public void setTitle(String title) {
	this.title = title;
}
public String getUrlNavigation() {
	System.out.println("navigation get => "+urlNavigation);
	return urlNavigation;
}
public void setUrlNavigation(String urlNavigation) {
	this.urlNavigation = urlNavigation;
}
  
  
  
	
	
}
